<template>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="font-weight:600;">文章编辑</span>
      </div>
      <el-form :label-position="'right'" label-width="80px" :model="formLabelAlign" ref="ruleForm">
        <el-form-item label="名称" prop="name"
        :rules="[
      { required: true, message: '文章名称不能为空'}
         ]"
        
        >
          <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item>
        <el-form-item label="内容" prop="content"
        :rules="[
      { required: true, message: '文章内容不能为空'}
         ]"
        
        >
          <el-input v-model="formLabelAlign.content"
           type="textarea"
          maxlength="300"
          :rows="10"
          show-word-limit
          ></el-input>
        </el-form-item>
         <el-form-item class="articlebtn">
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
      </el-form>
    </el-card>
   
</template>

<script>
export default {
  created() {
    // console.log(this.$message)
    // this.$ajax.getTest()
    // .then(res=>{
    //   console.log(res)
    // })
  },
  data(){
    return {
      formLabelAlign:{
        name:'',
        content:''
      }
    }
  },
  methods: {
      editArticle(){
        console.log(this.formLabelAlign.name,this.formLabelAlign.content)
        this.$ajax.editArticle({
          name:this.formLabelAlign.name,
          content:this.formLabelAlign.content
        })
        .then(res=>{
          console.log(res)
          if(res.data.msg==='success')
          {
            this.$message({
              type:'success',
              message:'编辑成功'
            })
            this.resetForm('ruleForm')
            this.$router.push({
              name:'article'
            })
          }
          
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          // console.log(valid)
          if (valid) {
            // alert('submit!');
            this.editArticle()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>

<style scoped>
  
</style>
